package cn.sylinx.hbatis.db.dialect.fs;

import java.util.HashMap;
import java.util.Map;

import cn.sylinx.hbatis.db.dialect.DbType;

public class FluentSqlCreatorFactory {

	private final Map<DbType, FluentSqlCreator> registers = new HashMap<DbType, FluentSqlCreator>();

	private static final FluentSqlCreatorFactory instance = new FluentSqlCreatorFactory();

	private final FluentSqlCreator defaultFluentSqlCreator = new DefaultFluentSqlCreator();

	public static FluentSqlCreatorFactory get() {
		return instance;
	}

	private FluentSqlCreatorFactory() {
		registerDefault();
	}

	/**
	 * 注册 FluentSqlCreator
	 */
	private void registerDefault() {

		register(DbType.MYSQL, new MysqlFluentSqlCreator());
		register(DbType.ORACLE, new OracleFluentSqlCreator());
		register(DbType.SQLSERVER, new SqlserverFluentSqlCreator());
	}

	public void register(DbType dbType, FluentSqlCreator sqlBuilder) {
		registers.put(dbType, sqlBuilder);
	}

	public FluentSqlCreator getFluentSqlCreator(DbType dbType) {
		FluentSqlCreator sb = registers.get(dbType);
		if (sb == null) {
			return defaultFluentSqlCreator;
		}
		return sb;
	}
}
